
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>ffmpeg示例代码 · Aivin开发笔记</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="Aivin">
        
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search-plus/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-anchor-navigation-ex/style/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-versions-select/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-tbfed-pagefooter/footer.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-donate/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-local-video/video-js.min.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-splitter/splitter.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-theme-comscore/test.css">
                
            
        

    

    
        
        <link rel="stylesheet" href="../../styles/website.css">
        
    

        
    
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="ffmpeg软解rtsp简单直播.html" />
    
    
    <link rel="prev" href="ffmpeg基础.html" />
    

    
        <link rel="shortcut icon" href='../../assets/images/favicon.ico' type="image/x-icon">
    
    
        <link rel="bookmark" href='../../assets/images/favicon.ico' type="image/x-icon">
    
    
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../">
            
                <a href="../../">
            
                    
                    项目说明
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../linux/linux基础.html">
            
                <a href="../linux/linux基础.html">
            
                    
                    linux
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../linux/linux基础.html">
            
                <a href="../linux/linux基础.html">
            
                    
                    linux基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="../linux/android底层开发.html">
            
                <a href="../linux/android底层开发.html">
            
                    
                    android底层开发
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../c语言/c基础.html">
            
                <a href="../c语言/c基础.html">
            
                    
                    c
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../c语言/c基础.html">
            
                <a href="../c语言/c基础.html">
            
                    
                    c基础
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../c++/c++基础.html">
            
                <a href="../c++/c++基础.html">
            
                    
                    c++
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../c++/c++基础.html">
            
                <a href="../c++/c++基础.html">
            
                    
                    c++基础
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../QT/QT基础.html">
            
                <a href="../QT/QT基础.html">
            
                    
                    QT
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="../QT/QT基础.html">
            
                <a href="../QT/QT基础.html">
            
                    
                    QT基础
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../jni/JNI基础.html">
            
                <a href="../jni/JNI基础.html">
            
                    
                    JNI
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="../jni/JNI基础.html">
            
                <a href="../jni/JNI基础.html">
            
                    
                    JNI基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="../jni/JNI例子.html">
            
                <a href="../jni/JNI例子.html">
            
                    
                    JNI例子
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../SDL/SDL基础.html">
            
                <a href="../SDL/SDL基础.html">
            
                    
                    SDL
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="../SDL/SDL基础.html">
            
                <a href="../SDL/SDL基础.html">
            
                    
                    SDL基础
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="ffmpeg基础.html">
            
                <a href="ffmpeg基础.html">
            
                    
                    ffmpeg
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.8.1" data-path="ffmpeg基础.html">
            
                <a href="ffmpeg基础.html">
            
                    
                    ffmpeg基础
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.8.2" data-path="ffmpeg示例代码.html">
            
                <a href="ffmpeg示例代码.html">
            
                    
                    ffmpeg示例代码
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.3" data-path="ffmpeg软解rtsp简单直播.html">
            
                <a href="ffmpeg软解rtsp简单直播.html">
            
                    
                    ffmpeg软解rtsp简单直播
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.4" data-path="rtsp服务器.html">
            
                <a href="rtsp服务器.html">
            
                    
                    rtsp服务器Windows
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="../opencv/opencv模块.html">
            
                <a href="../opencv/opencv模块.html">
            
                    
                    opencv模块
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.9.1" data-path="../opencv/opencv.html">
            
                <a href="../opencv/opencv.html">
            
                    
                    opencv
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="../openSLES/openSLES基础.html">
            
                <a href="../openSLES/openSLES基础.html">
            
                    
                    openSLES
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.10.1" data-path="../openSLES/openSLES基础.html">
            
                <a href="../openSLES/openSLES基础.html">
            
                    
                    openSLES基础
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.11" data-path="../SoundTouch/移植SoundTouch.html">
            
                <a href="../SoundTouch/移植SoundTouch.html">
            
                    
                    SoundTouch
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.11.1" data-path="../SoundTouch/移植SoundTouch.html">
            
                <a href="../SoundTouch/移植SoundTouch.html">
            
                    
                    移植SoundTouch
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.2" data-path="../SoundTouch/实现音频变速和变调.html">
            
                <a href="../SoundTouch/实现音频变速和变调.html">
            
                    
                    实现音频变速和变调
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.12" data-path="../openGLES/openGLES基础.html">
            
                <a href="../openGLES/openGLES基础.html">
            
                    
                    openGLES模块
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.12.1" data-path="../openGLES/openGLES基础.html">
            
                <a href="../openGLES/openGLES基础.html">
            
                    
                    openGLES基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.2" data-path="../openGLES/GLSL基础.html">
            
                <a href="../openGLES/GLSL基础.html">
            
                    
                    GLSL基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.3" data-path="../openGLES/openglES示例.html">
            
                <a href="../openGLES/openglES示例.html">
            
                    
                    openglES示例
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.13" data-path="../视频相关/音视频基础.html">
            
                <a href="../视频相关/音视频基础.html">
            
                    
                    音视频术语-文件格式-协议
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.13.1" data-path="../视频相关/音视频基础.html">
            
                <a href="../视频相关/音视频基础.html">
            
                    
                    音视频基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.2" data-path="../视频相关/RTSP.html">
            
                <a href="../视频相关/RTSP.html">
            
                    
                    RTSP
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.3" data-path="../视频相关/RTP.html">
            
                <a href="../视频相关/RTP.html">
            
                    
                    RTP
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.4" data-path="../视频相关/RTCP.html">
            
                <a href="../视频相关/RTCP.html">
            
                    
                    RTCP
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.5" data-path="../视频相关/H264.html">
            
                <a href="../视频相关/H264.html">
            
                    
                    H264
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.6" data-path="../视频相关/YUV.html">
            
                <a href="../视频相关/YUV.html">
            
                    
                    YUV
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.7" data-path="../视频相关/SurfaceView.html">
            
                <a href="../视频相关/SurfaceView.html">
            
                    
                    SurfaceView
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.8" data-path="../视频相关/RTMP.html">
            
                <a href="../视频相关/RTMP.html">
            
                    
                    RTMP
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.9" data-path="../视频相关/AAC详解.html">
            
                <a href="../视频相关/AAC详解.html">
            
                    
                    AAC详解
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.14" data-path="../音视频相关代码/音视频相关代码.html">
            
                <a href="../音视频相关代码/音视频相关代码.html">
            
                    
                    音视频相关代码
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15" data-path="../ndk/NDK编译基础.html">
            
                <a href="../ndk/NDK编译基础.html">
            
                    
                    NDK工程编译
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.15.1" data-path="../ndk/NDK编译基础.html">
            
                <a href="../ndk/NDK编译基础.html">
            
                    
                    NDK编译基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.2" data-path="../ndk/cmake方式.html">
            
                <a href="../ndk/cmake方式.html">
            
                    
                    cmake
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.3" data-path="../ndk/Android.mk模板.html">
            
                <a href="../ndk/Android.mk模板.html">
            
                    
                    Android.mk
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.4" data-path="../ndk/Application.mk模板.html">
            
                <a href="../ndk/Application.mk模板.html">
            
                    
                    Application.mk
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../.." >ffmpeg示例代码</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div class="search-plus" id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <div id="anchor-navigation-ex-navbar"><i class="fa fa-navicon"></i><ul><li><span class="title-icon "></span><a href="#ffmpeg&#x793A;&#x4F8B;"><b>1. </b>ffmpeg&#x793A;&#x4F8B;</a></li><ul><li><span class="title-icon "></span><a href="#&#x5E38;&#x7528;ffmpeg&#x4EE3;&#x7801;&#x7247;&#x6BB5;"><b>1.1. </b>&#x5E38;&#x7528;ffmpeg&#x4EE3;&#x7801;&#x7247;&#x6BB5;</a></li><ul><li><span class="title-icon "></span><a href="#&#x5BFC;&#x5165;&#x5934;&#x6587;&#x4EF6;"><b>1.1.1. </b>&#x5BFC;&#x5165;&#x5934;&#x6587;&#x4EF6;</a></li><li><span class="title-icon "></span><a href="#&#x904D;&#x5386;-avcodec"><b>1.1.2. </b>&#x904D;&#x5386; AVCodec</a></li><li><span class="title-icon "></span><a href="#&#x914D;&#x7F6E;&#x4FE1;&#x606F;"><b>1.1.3. </b>&#x914D;&#x7F6E;&#x4FE1;&#x606F;</a></li><li><span class="title-icon "></span><a href="#&#x904D;&#x5386;avinputformat"><b>1.1.4. </b>&#x904D;&#x5386;AVInputFormat</a></li><li><span class="title-icon "></span><a href="#&#x904D;&#x5386;avoutputformat"><b>1.1.5. </b>&#x904D;&#x5386;AVOutputFormat</a></li><li><span class="title-icon "></span><a href="#&#x904D;&#x5386;-avfilter"><b>1.1.6. </b>&#x904D;&#x5386; AVFilter</a></li><li><span class="title-icon "></span><a href="#mp3-&#x8F6C;-aac"><b>1.1.7. </b>mp3 &#x8F6C; aac</a></li><li><span class="title-icon "></span><a href="#&#x97F3;&#x9891;&#x89E3;&#x7801;--&#x64AD;&#x653E;"><b>1.1.8. </b>&#x97F3;&#x9891;&#x89E3;&#x7801; + &#x64AD;&#x653E;</a></li><li><span class="title-icon "></span><a href="#native-ffmpeg-&#x5B9E;&#x73B0;&#x89E3;&#x7801;-&#xFF0C;-native-&#x5C42;&#x7684;-opensl-&#x5B9E;&#x73B0;&#x64AD;&#x653E;"><b>1.1.9. </b>native ffmpeg &#x5B9E;&#x73B0;&#x89E3;&#x7801; &#xFF0C; native &#x5C42;&#x7684; opensl &#x5B9E;&#x73B0;&#x64AD;&#x653E;</a></li><li><span class="title-icon "></span><a href="#&#x64AD;&#x653E;&#x672C;&#x5730;mp4"><b>1.1.10. </b>&#x64AD;&#x653E;&#x672C;&#x5730;MP4</a></li></ul></ul></ul></div><a href="#ffmpeg&#x793A;&#x4F8B;" id="anchorNavigationExGoTop"><i class="fa fa-arrow-up"></i></a><h1 id="ffmpeg&#x793A;&#x4F8B;"><a name="ffmpeg&#x793A;&#x4F8B;" class="anchor-navigation-ex-anchor" href="#ffmpeg&#x793A;&#x4F8B;"><i class="fa fa-link" aria-hidden="true"></i></a>1. ffmpeg&#x793A;&#x4F8B;</h1>
<h2 id="&#x5E38;&#x7528;ffmpeg&#x4EE3;&#x7801;&#x7247;&#x6BB5;"><a name="&#x5E38;&#x7528;ffmpeg&#x4EE3;&#x7801;&#x7247;&#x6BB5;" class="anchor-navigation-ex-anchor" href="#&#x5E38;&#x7528;ffmpeg&#x4EE3;&#x7801;&#x7247;&#x6BB5;"><i class="fa fa-link" aria-hidden="true"></i></a>1.1. &#x5E38;&#x7528;ffmpeg&#x4EE3;&#x7801;&#x7247;&#x6BB5;</h2>
<h3 id="&#x5BFC;&#x5165;&#x5934;&#x6587;&#x4EF6;"><a name="&#x5BFC;&#x5165;&#x5934;&#x6587;&#x4EF6;" class="anchor-navigation-ex-anchor" href="#&#x5BFC;&#x5165;&#x5934;&#x6587;&#x4EF6;"><i class="fa fa-link" aria-hidden="true"></i></a>1.1.1. &#x5BFC;&#x5165;&#x5934;&#x6587;&#x4EF6;</h3>
<pre><code class="lang-c"><span class="hljs-keyword">extern</span> <span class="hljs-string">&quot;C&quot;</span>
{
<span class="hljs-meta">#<span class="hljs-meta-keyword">include</span> <span class="hljs-meta-string">&lt;libavcodec/avcodec.h&gt;</span></span>
}
</code></pre>
<h3 id="&#x904D;&#x5386;-avcodec"><a name="&#x904D;&#x5386;-avcodec" class="anchor-navigation-ex-anchor" href="#&#x904D;&#x5386;-avcodec"><i class="fa fa-link" aria-hidden="true"></i></a>1.1.2. &#x904D;&#x5386; AVCodec</h3>
<pre><code class="lang-c">av_register_all();
AVCodec * codec= av_codec_next(<span class="hljs-literal">NULL</span>) ;
<span class="hljs-keyword">while</span>(codec !=<span class="hljs-literal">NULL</span>)
{
    LOGI(<span class="hljs-string">&quot;&#x4FE1;&#x606F; codec-&gt;type =%s&quot;</span> , codec-&gt;name) ;
    <span class="hljs-comment">// &#x83B7;&#x53D6;&#x4E0B;&#x4E00;&#x4E2A;</span>
    codec = codec-&gt;next ;
}
</code></pre>
<h3 id="&#x914D;&#x7F6E;&#x4FE1;&#x606F;"><a name="&#x914D;&#x7F6E;&#x4FE1;&#x606F;" class="anchor-navigation-ex-anchor" href="#&#x914D;&#x7F6E;&#x4FE1;&#x606F;"><i class="fa fa-link" aria-hidden="true"></i></a>1.1.3. &#x914D;&#x7F6E;&#x4FE1;&#x606F;</h3>
<pre><code class="lang-c"><span class="hljs-keyword">const</span> <span class="hljs-keyword">char</span>* configuration  = avcodec_configuration() ;
LOGI(<span class="hljs-string">&quot;&#x914D;&#x7F6E;&#x4FE1;&#x606F;configuration =%s&quot;</span> , configuration) ;
</code></pre>
<h3 id="&#x904D;&#x5386;avinputformat"><a name="&#x904D;&#x5386;avinputformat" class="anchor-navigation-ex-anchor" href="#&#x904D;&#x5386;avinputformat"><i class="fa fa-link" aria-hidden="true"></i></a>1.1.4. &#x904D;&#x5386;AVInputFormat</h3>
<pre><code class="lang-c">av_register_all();
<span class="hljs-keyword">char</span> * info = (<span class="hljs-keyword">char</span> * )<span class="hljs-built_in">malloc</span>(<span class="hljs-number">40000</span>);
<span class="hljs-built_in">memset</span>(info,<span class="hljs-number">0</span>,<span class="hljs-number">40000</span>);
AVInputFormat *if_temp = av_iformat_next(<span class="hljs-literal">NULL</span> );
<span class="hljs-keyword">while</span>(if_temp!=<span class="hljs-literal">NULL</span>){
    <span class="hljs-built_in">sprintf</span>(info, <span class="hljs-string">&quot;===%s   &quot;</span>, if_temp-&gt;name );
    LOGI(<span class="hljs-string">&quot;&#x4FE1;&#x606F; AVInputFormat =%s&quot;</span> , info ) ;
    if_temp=if_temp-&gt;next ;
}
</code></pre>
<h3 id="&#x904D;&#x5386;avoutputformat"><a name="&#x904D;&#x5386;avoutputformat" class="anchor-navigation-ex-anchor" href="#&#x904D;&#x5386;avoutputformat"><i class="fa fa-link" aria-hidden="true"></i></a>1.1.5. &#x904D;&#x5386;AVOutputFormat</h3>
<pre><code class="lang-c">av_register_all();
<span class="hljs-keyword">char</span> *info=(<span class="hljs-keyword">char</span> * )<span class="hljs-built_in">malloc</span>(<span class="hljs-number">40000</span>);
<span class="hljs-built_in">memset</span>(info,<span class="hljs-number">0</span>,<span class="hljs-number">40000</span>);
AVOutputFormat *of_temp  = av_oformat_next(<span class="hljs-literal">NULL</span>);
<span class="hljs-keyword">while</span>(of_temp!=<span class="hljs-literal">NULL</span>){
    <span class="hljs-built_in">sprintf</span>(info, <span class="hljs-string">&quot;===%s   &quot;</span>, of_temp-&gt;name);
    LOGI(<span class="hljs-string">&quot;&#x4FE1;&#x606F; AVOutputFormat =%s&quot;</span> , info) ;
    of_temp=of_temp-&gt;next;
}
</code></pre>
<h3 id="&#x904D;&#x5386;-avfilter"><a name="&#x904D;&#x5386;-avfilter" class="anchor-navigation-ex-anchor" href="#&#x904D;&#x5386;-avfilter"><i class="fa fa-link" aria-hidden="true"></i></a>1.1.6. &#x904D;&#x5386; AVFilter</h3>
<pre><code class="lang-c">avfilter_register_all();
<span class="hljs-keyword">char</span> *info=(<span class="hljs-keyword">char</span> * )<span class="hljs-built_in">malloc</span>(<span class="hljs-number">40000</span>);
<span class="hljs-built_in">memset</span>(info,<span class="hljs-number">0</span>,<span class="hljs-number">40000</span>);

AVFilter * f_temp = (AVFilter * )avfilter_next(<span class="hljs-literal">NULL</span>);
<span class="hljs-keyword">while</span> (f_temp != <span class="hljs-literal">NULL</span>){
    <span class="hljs-built_in">sprintf</span>(info, <span class="hljs-string">&quot;%s&quot;</span>,  f_temp-&gt;name);
    LOGI(<span class="hljs-string">&quot;&#x4FE1;&#x606F; AVFilter =%s&quot;</span> , info) ;
    f_temp=f_temp-&gt;next;
}
</code></pre>
<h3 id="mp3-&#x8F6C;-aac"><a name="mp3-&#x8F6C;-aac" class="anchor-navigation-ex-anchor" href="#mp3-&#x8F6C;-aac"><i class="fa fa-link" aria-hidden="true"></i></a>1.1.7. mp3 &#x8F6C; aac</h3>
<pre><code class="lang-c">// &#x8F6C;&#x6362;&#x547D;&#x4EE4;
ffmpeg -i xxx.mp3  xxx.aac

JNIEXPORT jint xxxxxxxxxxxMp3ToAAC
(JNIEnv * env, jclass obj, jobjectArray commands)
{
    int argc = ( * env)-&gt;GetArrayLength(env, commands);
    char **argv = (char * * )malloc(argc * sizeof(char* ));
    int i;
    int result;
    for (i = 0; i &lt; argc; i++)
    {
        jstring jstr = (jstring) (* env)-&gt;GetObjectArrayElement(env, commands, i);
        char* temp = (char* ) (* env)-&gt;GetStringUTFChars(env, jstr, 0);
        argv[i] = malloc(1024);
        strcpy(argv[i], temp);
        (*env)-&gt;ReleaseStringUTFChars(env, jstr, temp);
    }
    //&#x6267;&#x884C;ffmpeg&#x547D;&#x4EE4; ,  &#x5C06;&#x6E90;&#x7801;&#x4E2D;&#x7684; main() &#x6539;&#x6210;run()
    result =  run(argc, argv);
    //&#x91CA;&#x653E;&#x5185;&#x5B58;
    for (i = 0; i &lt; argc; i++)
    {
        free(argv[i]);
    }
    free(argv);
    return result;
}
</code></pre>
<h3 id="&#x97F3;&#x9891;&#x89E3;&#x7801;--&#x64AD;&#x653E;"><a name="&#x97F3;&#x9891;&#x89E3;&#x7801;--&#x64AD;&#x653E;" class="anchor-navigation-ex-anchor" href="#&#x97F3;&#x9891;&#x89E3;&#x7801;--&#x64AD;&#x653E;"><i class="fa fa-link" aria-hidden="true"></i></a>1.1.8. &#x97F3;&#x9891;&#x89E3;&#x7801; + &#x64AD;&#x653E;</h3>
<p>native ffmpeg &#x5B9E;&#x73B0;&#x89E3;&#x7801; &#xFF0C; java&#x5C42;&#x7684; AudioTrack &#x5B9E;&#x73B0;&#x64AD;&#x653E;</p>
<pre><code class="lang-c"><span class="hljs-meta">#<span class="hljs-meta-keyword">define</span> MAX_AUDIO_FRAME_SIZE 48000 * 4</span>
<span class="hljs-function">JNIEXPORT <span class="hljs-keyword">void</span> JNICALL <span class="hljs-title">Java_xxxx_play</span>
  <span class="hljs-params">(JNIEnv *env, jobject jthiz, jstring input_jstr)</span></span>{
    <span class="hljs-keyword">const</span> <span class="hljs-keyword">char</span>* input_cstr = (*env)-&gt;GetStringUTFChars(env,input_jstr,<span class="hljs-literal">NULL</span>);
    <span class="hljs-comment">//&#x6CE8;&#x518C;&#x7EC4;&#x4EF6;</span>
    av_register_all();
    AVFormatContext *pFormatCtx = avformat_alloc_context();
    <span class="hljs-comment">//&#x6253;&#x5F00;&#x97F3;&#x9891;&#x6587;&#x4EF6;</span>
    <span class="hljs-keyword">if</span>(avformat_open_input(&amp;pFormatCtx,input_cstr,<span class="hljs-literal">NULL</span>,<span class="hljs-literal">NULL</span>) != <span class="hljs-number">0</span>)
    {
        <span class="hljs-keyword">return</span>;
    }
    <span class="hljs-comment">//&#x83B7;&#x53D6;&#x8F93;&#x5165;&#x6587;&#x4EF6;&#x4FE1;&#x606F;</span>
    <span class="hljs-keyword">if</span>(avformat_find_stream_info(pFormatCtx,<span class="hljs-literal">NULL</span>) &lt; <span class="hljs-number">0</span>){
        <span class="hljs-keyword">return</span>;
    }
    <span class="hljs-comment">//&#x83B7;&#x53D6;&#x97F3;&#x9891;&#x6D41;&#x7D22;&#x5F15;&#x4F4D;&#x7F6E;</span>
    <span class="hljs-keyword">int</span>  audio_stream_idx = <span class="hljs-number">-1</span>;
    <span class="hljs-keyword">for</span>(<span class="hljs-keyword">int</span> i=<span class="hljs-number">0</span>; i &lt; pFormatCtx-&gt;nb_streams;i++)
    {
        <span class="hljs-keyword">if</span>(pFormatCtx-&gt;streams[i]-&gt;codec-&gt;codec_type == AVMEDIA_TYPE_AUDIO)
        {
            audio_stream_idx = i;
            <span class="hljs-keyword">break</span>;
        }
    }

    <span class="hljs-comment">//&#x83B7;&#x53D6;&#x97F3;&#x9891;&#x89E3;&#x7801;&#x5668;</span>
    AVCodecContext *codecCtx = pFormatCtx-&gt;streams[audio_stream_idx]-&gt;codec;
    AVCodec *codec = avcodec_find_decoder(codecCtx-&gt;codec_id);
    <span class="hljs-keyword">if</span>(codec == <span class="hljs-literal">NULL</span>)
    {
        <span class="hljs-keyword">return</span>;
    }
    <span class="hljs-comment">//&#x6253;&#x5F00;&#x89E3;&#x7801;&#x5668;</span>
    <span class="hljs-keyword">if</span>(avcodec_open2(codecCtx,codec,<span class="hljs-literal">NULL</span>) &lt; <span class="hljs-number">0</span>)
    {
        <span class="hljs-keyword">return</span>;
    }
    <span class="hljs-comment">//&#x89E3;&#x7801;&#x4E4B;&#x524D;&#x7684;&#x6570;&#x636E;</span>
    AVPacket *packet = (AVPacket *)av_malloc(<span class="hljs-keyword">sizeof</span>(AVPacket));
    <span class="hljs-comment">//&#x89E3;&#x7801;&#x4E4B;&#x540E;&#x7684;&#x6570;&#x636E;</span>
    AVFrame *frame = av_frame_alloc();

    <span class="hljs-comment">//&#x8F93;&#x5165;&#x7684;&#x91C7;&#x6837;&#x683C;&#x5F0F;</span>
    <span class="hljs-keyword">enum</span> AVSampleFormat in_sample_fmt = codecCtx-&gt;sample_fmt;
    <span class="hljs-comment">//&#x8F93;&#x51FA;&#x91C7;&#x6837;&#x683C;&#x5F0F;16bit PCM</span>
    <span class="hljs-keyword">enum</span> AVSampleFormat out_sample_fmt = AV_SAMPLE_FMT_S16;
    <span class="hljs-comment">//&#x8F93;&#x5165;&#x91C7;&#x6837;&#x7387;</span>
    <span class="hljs-keyword">int</span> in_sample_rate = codecCtx-&gt;sample_rate;
    <span class="hljs-comment">//&#x8F93;&#x51FA;&#x91C7;&#x6837;&#x7387;</span>
    <span class="hljs-keyword">int</span> out_sample_rate = in_sample_rate;
    <span class="hljs-comment">//&#x58F0;&#x9053;&#x5E03;&#x5C40;&#xFF08;2&#x4E2A;&#x58F0;&#x9053;&#xFF0C;&#x9ED8;&#x8BA4;&#x7ACB;&#x4F53;&#x58F0;stereo&#xFF09;</span>
    <span class="hljs-keyword">uint64_t</span> in_ch_layout = codecCtx-&gt;channel_layout;
    <span class="hljs-comment">//&#x8F93;&#x51FA;&#x7684;&#x58F0;&#x9053;&#x5E03;&#x5C40;&#xFF08;&#x7ACB;&#x4F53;&#x58F0;&#xFF09;</span>
    <span class="hljs-keyword">uint64_t</span> out_ch_layout = AV_CH_LAYOUT_STEREO;
    <span class="hljs-comment">//&#x8F93;&#x51FA;&#x7684;&#x58F0;&#x9053;&#x4E2A;&#x6570;</span>
    <span class="hljs-keyword">int</span> out_channel_nb = av_get_channel_layout_nb_channels(out_ch_layout);
    <span class="hljs-comment">//&#x97F3;&#x9891;&#x91CD;&#x91C7;&#x6837;</span>
    SwrContext *swrCtx = swr_alloc();
    swr_alloc_set_opts(swrCtx,
          out_ch_layout,out_sample_fmt,out_sample_rate,
          in_ch_layout,in_sample_fmt,in_sample_rate,
          <span class="hljs-number">0</span>, <span class="hljs-literal">NULL</span>);
    swr_init(swrCtx);

    <span class="hljs-comment">// &#x83B7;&#x53D6;&#x8C03;&#x7528;&#x8FD9;&#x4E2A;c&#x6587;&#x4EF6;&#x7684;java&#x6587;&#x4EF6;&#x7C7B;</span>
    jclass player_class = (*env)-&gt;GetObjectClass(env,jthiz);
    <span class="hljs-keyword">if</span>(!player_class){
        <span class="hljs-keyword">return</span>;
    }
    <span class="hljs-comment">//&#x627E;&#x5230; java&#x4EE3;&#x7801;&#x4E2D;&#x7684;  public AudioTrack createAudioTrack(int sampleRate, int channels) &#x65B9;&#x6CD5;</span>
    jmethodID audio_track_method = (*env)-&gt;GetMethodID(env,player_class,<span class="hljs-string">&quot;createAudioTrack&quot;</span>,<span class="hljs-string">&quot;(II)Landroid/media/AudioTrack;&quot;</span>);
    <span class="hljs-keyword">if</span>(!audio_track_method){
        <span class="hljs-keyword">return</span>;
    }
    <span class="hljs-comment">// &#x4F7F;&#x7528;java&#x4E2D;&#x5BF9;&#x5E94;&#x7684;&#x65B9;&#x6CD5;</span>
    jobject audio_track = (*env)-&gt;CallObjectMethod(env,jthiz,audio_track_method,out_sample_rate,out_channel_nb);

    <span class="hljs-comment">//&#x8C03;&#x7528;AudioTrack &#x7684; play() &#x65B9;&#x6CD5;</span>
    jclass audio_track_class = (*env)-&gt;GetObjectClass(env,audio_track);
    jmethodID audio_track_play_mid = (*env)-&gt;GetMethodID(env,audio_track_class,<span class="hljs-string">&quot;play&quot;</span>,<span class="hljs-string">&quot;()V&quot;</span>);
    (*env)-&gt;CallVoidMethod(env,audio_track,audio_track_play_mid);

    <span class="hljs-comment">//&#x8F6C;&#x6362;&#x683C;&#x5F0F;&#x540E;&#x7684;&#x6570;&#x636E;</span>
    <span class="hljs-keyword">uint8_t</span> *out_buffer = (<span class="hljs-keyword">uint8_t</span> *)av_malloc(MAX_AUDIO_FRAME_SIZE);

    <span class="hljs-keyword">int</span> got_frame = <span class="hljs-number">0</span> ;
    <span class="hljs-comment">//&#x4E0D;&#x65AD;&#x8BFB;&#x53D6;&#x7F16;&#x7801;&#x6570;&#x636E;</span>
    <span class="hljs-keyword">while</span> (av_read_frame(pFormatCtx, packet) &gt;= <span class="hljs-number">0</span>)
    {
        <span class="hljs-keyword">if</span> (packet-&gt;stream_index == audio_stream_idx)
        {
            <span class="hljs-comment">//&#x97F3;&#x9891;&#x89E3;&#x7801;</span>
            <span class="hljs-keyword">int</span> ret = avcodec_decode_audio4(codecCtx, frame, &amp;got_frame, packet);
            <span class="hljs-keyword">if</span> (ret &lt; <span class="hljs-number">0</span>)
            {
                <span class="hljs-keyword">break</span>;
            }
            <span class="hljs-comment">//&#x89E3;&#x7801;&#x4E00;&#x5E27;&#x6210;&#x529F;</span>
            <span class="hljs-keyword">if</span> (got_frame &gt; <span class="hljs-number">0</span>)
            {
                <span class="hljs-comment">//&#x97F3;&#x9891;&#x683C;&#x5F0F;&#x8F6C;&#x6362;</span>
                swr_convert(swrCtx, &amp;out_buffer, MAX_AUDIO_FRAME_SIZE, (<span class="hljs-keyword">const</span> <span class="hljs-keyword">uint8_t</span> **) frame-&gt;data, frame-&gt;nb_samples);
                <span class="hljs-keyword">int</span> out_buffer_size = av_samples_get_buffer_size(<span class="hljs-literal">NULL</span>,
                                                                 out_channel_nb,
                                                                 frame-&gt;nb_samples,
                                                                 out_sample_fmt,
                                                                 <span class="hljs-number">1</span>);

                jbyteArray audio_sample_array = (*env)-&gt;NewByteArray(env, out_buffer_size);
                jbyte *sample_byte_array = (*env)-&gt;GetByteArrayElements(env, audio_sample_array,
                                                                        <span class="hljs-literal">NULL</span>);
                <span class="hljs-comment">//&#x62F7;&#x8D1D;&#x7F13;&#x51B2;&#x6570;&#x636E;</span>
                <span class="hljs-built_in">memcpy</span>(sample_byte_array, out_buffer, (<span class="hljs-keyword">size_t</span>) out_buffer_size);
                <span class="hljs-comment">//&#x91CA;&#x653E;&#x6570;&#x7EC4;</span>
                (*env)-&gt;ReleaseByteArrayElements(env, audio_sample_array, sample_byte_array, <span class="hljs-number">0</span>);

                <span class="hljs-comment">//&#x8C03;&#x7528;AudioTrack &#x7684; &#x83B7;&#x53D6;write(...)&#x65B9;&#x6CD5;&#x8FDB;&#x884C;&#x64AD;&#x653E;</span>
                jmethodID audio_track_write_mid = (*env)-&gt;GetMethodID(env, audio_track_class,
                                                                      <span class="hljs-string">&quot;write&quot;</span>, <span class="hljs-string">&quot;([BII)I&quot;</span>);
                (*env)-&gt;CallIntMethod(env,
                                      audio_track,
                                      audio_track_write_mid,
                                      audio_sample_array,
                                      <span class="hljs-number">0</span>,
                                      out_buffer_size);
                <span class="hljs-comment">//&#x91CA;&#x653E;&#x5C40;&#x90E8;&#x5F15;&#x7528;</span>
                (*env)-&gt;DeleteLocalRef(env, audio_sample_array);
                usleep(<span class="hljs-number">1000</span> * <span class="hljs-number">16</span>);
            }
        }
        av_free_packet(packet);
    }

    av_frame_free(&amp;frame);
    av_free(out_buffer);
    swr_free(&amp;swrCtx);
    avcodec_close(codecCtx);
    avformat_close_input(&amp;pFormatCtx);
    (*env)-&gt;ReleaseStringUTFChars(env,input_jstr,input_cstr);
}


<span class="hljs-function"><span class="hljs-keyword">public</span> AudioTrack <span class="hljs-title">createAudioTrack</span><span class="hljs-params">(<span class="hljs-keyword">int</span> sampleRate, <span class="hljs-keyword">int</span> channels)</span></span>{
    <span class="hljs-keyword">int</span> audioFormat = AudioFormat.ENCODING_PCM_16BIT;
    <span class="hljs-keyword">int</span> channelConfig;
    <span class="hljs-keyword">if</span>(channels == <span class="hljs-number">1</span>){
        <span class="hljs-comment">// &#x5355;&#x58F0;&#x9053;</span>
        channelConfig = AudioFormat.CHANNEL_OUT_MONO;
    }<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span>(channels == <span class="hljs-number">2</span>){
        <span class="hljs-comment">// &#x8F93;&#x51FA;&#x58F0;&#x9053;&#x4E3A;&#x53CC;&#x58F0;&#x9053;&#x7ACB;&#x4F53;&#x58F0;</span>
        channelConfig = AudioFormat.CHANNEL_OUT_STEREO;
    }<span class="hljs-keyword">else</span>{
        channelConfig = AudioFormat.CHANNEL_OUT_STEREO;
    }
    <span class="hljs-comment">// sampleRate  &#x91C7;&#x6837;&#x7387;</span>
    <span class="hljs-keyword">int</span> bufferSizeInBytes = AudioTrack.getMinBufferSize(sampleRate, channelConfig, audioFormat);
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> AudioTrack(AudioManager.STREAM_MUSIC,
            sampleRate, channelConfig, audioFormat,bufferSizeInBytes, AudioTrack.MODE_STREAM);
}
</code></pre>
<h3 id="native-ffmpeg-&#x5B9E;&#x73B0;&#x89E3;&#x7801;-&#xFF0C;-native-&#x5C42;&#x7684;-opensl-&#x5B9E;&#x73B0;&#x64AD;&#x653E;"><a name="native-ffmpeg-&#x5B9E;&#x73B0;&#x89E3;&#x7801;-&#xFF0C;-native-&#x5C42;&#x7684;-opensl-&#x5B9E;&#x73B0;&#x64AD;&#x653E;" class="anchor-navigation-ex-anchor" href="#native-ffmpeg-&#x5B9E;&#x73B0;&#x89E3;&#x7801;-&#xFF0C;-native-&#x5C42;&#x7684;-opensl-&#x5B9E;&#x73B0;&#x64AD;&#x653E;"><i class="fa fa-link" aria-hidden="true"></i></a>1.1.9. native ffmpeg &#x5B9E;&#x73B0;&#x89E3;&#x7801; &#xFF0C; native &#x5C42;&#x7684; opensl &#x5B9E;&#x73B0;&#x64AD;&#x653E;</h3>
<pre><code class="lang-c"><span class="hljs-comment">//OpenSLES - &#x5BF9;&#x8C61;&#x63A5;&#x53E3;-</span>
SLObjectItf engineObject = <span class="hljs-literal">NULL</span>;
<span class="hljs-comment">// OpenSLES - &#x5F15;&#x64CE;&#x63A5;&#x53E3;-</span>
SLEngineItf engineEngine;
<span class="hljs-comment">//&#x8F93;&#x51FA;&#x6DF7;&#x97F3;&#x5668;&#x63A5;&#x53E3;</span>
SLObjectItf outputMixObject = <span class="hljs-literal">NULL</span>;
<span class="hljs-comment">// &#x6DF7;&#x97F3;&#x5668;&#x73AF;&#x5883;&#x63A5;&#x53E3;</span>
SLEnvironmentalReverbItf outputMixEnvironmentalReverb = <span class="hljs-literal">NULL</span>;
<span class="hljs-comment">//&#x7F13;&#x51B2;&#x64AD;&#x653E;&#x5668;&#x63A5;&#x53E3;</span>
SLObjectItf bqPlayerObject = <span class="hljs-literal">NULL</span>;
<span class="hljs-comment">// &#x64AD;&#x653E;&#x63A5;&#x53E3;</span>
SLPlayItf bqPlayerPlay;
SLAndroidSimpleBufferQueueItf bqPlayerBufferQueue;
SLEffectSendItf bqPlayerEffectSend;
SLVolumeItf bqPlayerVolume;
<span class="hljs-comment">//&#x97F3;&#x6548;&#x8BBE;&#x7F6E;</span>
<span class="hljs-keyword">const</span> SLEnvironmentalReverbSettings reverbSettings = SL_I3DL2_ENVIRONMENT_PRESET_STONECORRIDOR;
<span class="hljs-keyword">void</span> *buffer;
<span class="hljs-keyword">size_t</span> bufferSize;
<span class="hljs-keyword">uint8_t</span> *outputBuffer;
<span class="hljs-comment">// &#x5206;&#x914D;PCM&#x6570;&#x636E;&#x7F13;&#x5B58;</span>
<span class="hljs-keyword">size_t</span> outputBufferSize;

<span class="hljs-comment">//FFmpeg&#x76F8;&#x5173;</span>
AVPacket packet;
<span class="hljs-comment">//&#x97F3;&#x9891;&#x6D41;&#x7D22;&#x5F15;&#x4F4D;&#x7F6E;</span>
<span class="hljs-keyword">int</span> audioStream;
AVFrame *aFrame;
SwrContext *swr;
AVFormatContext *aFormatCtx;
AVCodecContext *aCodecCtx;
<span class="hljs-keyword">int</span> frame_count = <span class="hljs-number">0</span>;
<span class="hljs-function"><span class="hljs-keyword">int</span> <span class="hljs-title">createAudioPlayer</span><span class="hljs-params">(<span class="hljs-keyword">int</span> *rate, <span class="hljs-keyword">int</span> *channel, <span class="hljs-keyword">const</span> <span class="hljs-keyword">char</span> *file_name)</span> </span>;
<span class="hljs-function"><span class="hljs-keyword">int</span> <span class="hljs-title">releaseAudioPlayer</span><span class="hljs-params">()</span></span>;
<span class="hljs-function"><span class="hljs-keyword">int</span> <span class="hljs-title">getPCM</span><span class="hljs-params">(<span class="hljs-keyword">void</span> **pcm, size_t *pcmSize)</span> </span>;

<span class="hljs-comment">//&#x64AD;&#x653E;&#x56DE;&#x8C03;&#x65B9;&#x6CD5;</span>
<span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">bqPlayerCallback</span><span class="hljs-params">(SLAndroidSimpleBufferQueueItf bufferQueueItf, <span class="hljs-keyword">void</span> *context)</span>
</span>{
    bufferSize = <span class="hljs-number">0</span>;
    getPCM(&amp;buffer, &amp;bufferSize);
    <span class="hljs-comment">//&#x5982;&#x679C;buffer&#x4E0D;&#x4E3A;&#x7A7A;&#xFF0C;&#x5165;&#x5F85;&#x64AD;&#x653E;&#x961F;&#x5217;</span>
    <span class="hljs-keyword">if</span> (<span class="hljs-literal">NULL</span> != buffer &amp;&amp; <span class="hljs-number">0</span> != bufferSize) {
        SLresult result;
        result = (*bqPlayerBufferQueue)-&gt;Enqueue(bqPlayerBufferQueue, buffer, bufferSize);
        <span class="hljs-keyword">if</span>(result &lt; <span class="hljs-number">0</span>){
            LOGE(<span class="hljs-string">&quot;Enqueue error...&quot;</span>);
        } <span class="hljs-keyword">else</span>{
            LOGI(<span class="hljs-string">&quot;decode frame count=%d&quot;</span>, frame_count++);
        }
    }
}

<span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">createEngine</span><span class="hljs-params">()</span>
</span>{
    <span class="hljs-comment">// &#x64CD;&#x4F5C;&#x7ED3;&#x679C;</span>
    SLresult result;
    <span class="hljs-comment">//&#x521B;&#x5EFA;&#x5F15;&#x64CE;</span>
    result = slCreateEngine(&amp;engineObject, <span class="hljs-number">0</span>, <span class="hljs-literal">NULL</span>, <span class="hljs-number">0</span>, <span class="hljs-literal">NULL</span>, <span class="hljs-literal">NULL</span>);
    result = (*engineObject)-&gt;Realize(engineObject, SL_BOOLEAN_FALSE);
    <span class="hljs-comment">//&#x83B7;&#x53D6;&#x5F15;&#x64CE;&#x63A5;&#x53E3;</span>
    result = (*engineObject)-&gt;GetInterface(engineObject, SL_IID_ENGINE, &amp;engineEngine);
    <span class="hljs-comment">//&#x521B;&#x5EFA;&#x8F93;&#x51FA;&#x6DF7;&#x97F3;&#x5668;</span>
    result = (*engineEngine)-&gt;CreateOutputMix(engineEngine, &amp;outputMixObject, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>);
    <span class="hljs-comment">//&#x5173;&#x8054;&#x8F93;&#x51FA;&#x6DF7;&#x97F3;&#x5668;</span>
    result = (*outputMixObject)-&gt;Realize(outputMixObject, SL_BOOLEAN_FALSE);
    <span class="hljs-comment">//&#x83B7;&#x53D6;reverb&#x63A5;&#x53E3;</span>
    result = (*outputMixObject)-&gt;GetInterface(outputMixObject,
                                              SL_IID_ENVIRONMENTALREVERB,
                                              &amp;outputMixEnvironmentalReverb);
    <span class="hljs-keyword">if</span> (SL_RESULT_SUCCESS == result)
    {
        result = (*outputMixEnvironmentalReverb)-&gt;SetEnvironmentalReverbProperties(
                outputMixEnvironmentalReverb, &amp;reverbSettings);
    }
}

<span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">createBufferQueueAudioPlayer</span><span class="hljs-params">(<span class="hljs-keyword">int</span> rate, <span class="hljs-keyword">int</span> channel, <span class="hljs-keyword">int</span> bitsPerSample)</span>
</span>{
    SLresult result;
    <span class="hljs-comment">//&#x914D;&#x7F6E;&#x97F3;&#x9891;&#x6E90;</span>
    SLDataLocator_AndroidSimpleBufferQueue buffer_queue = {SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE, <span class="hljs-number">2</span>};
    SLDataFormat_PCM format_pcm;
    format_pcm.formatType = SL_DATAFORMAT_PCM;
    format_pcm.numChannels = (SLuint32) channel;
    format_pcm.bitsPerSample = (SLuint32) bitsPerSample;
    format_pcm.samplesPerSec = (SLuint32) (rate * <span class="hljs-number">1000</span>);
    format_pcm.containerSize = <span class="hljs-number">16</span>;
    <span class="hljs-keyword">if</span> (channel == <span class="hljs-number">2</span>)
    {
        format_pcm.channelMask = SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT;
    } <span class="hljs-keyword">else</span>{
        format_pcm.channelMask = SL_SPEAKER_FRONT_CENTER;
    }
    format_pcm.endianness = SL_BYTEORDER_LITTLEENDIAN;
    SLDataSource audioSrc = {&amp;buffer_queue, &amp;format_pcm};
    <span class="hljs-comment">//&#x914D;&#x7F6E;&#x97F3;&#x9891;&#x6C60;</span>
    SLDataLocator_OutputMix loc_outmix = {SL_DATALOCATOR_OUTPUTMIX, outputMixObject};
    SLDataSink audioSnk = {&amp;loc_outmix, <span class="hljs-literal">NULL</span>};
    <span class="hljs-comment">//&#x521B;&#x5EFA;&#x97F3;&#x9891;&#x64AD;&#x653E;&#x5668;</span>
    <span class="hljs-keyword">const</span> SLInterfaceID ids[<span class="hljs-number">3</span>] = {SL_IID_BUFFERQUEUE, SL_IID_EFFECTSEND, SL_IID_VOLUME};
    <span class="hljs-keyword">const</span> SLboolean req[<span class="hljs-number">3</span>] = {SL_BOOLEAN_TRUE, SL_BOOLEAN_TRUE, SL_BOOLEAN_TRUE};
    result = (*engineEngine)-&gt;CreateAudioPlayer(engineEngine,
                                                &amp;bqPlayerObject,
                                                &amp;audioSrc,
                                                &amp;audioSnk,
                                                <span class="hljs-number">3</span>,
                                                ids,
                                                req);
    <span class="hljs-comment">//&#x5173;&#x8054;&#x64AD;&#x653E;&#x5668;</span>
    result = (*bqPlayerObject)-&gt;Realize(bqPlayerObject, SL_BOOLEAN_FALSE);
    <span class="hljs-comment">//&#x83B7;&#x53D6;&#x64AD;&#x653E;&#x63A5;&#x53E3;</span>
    result = (*bqPlayerObject)-&gt;GetInterface(bqPlayerObject, SL_IID_PLAY, &amp;bqPlayerPlay);
    <span class="hljs-comment">//&#x83B7;&#x53D6;&#x7F13;&#x51B2;&#x961F;&#x5217;&#x63A5;&#x53E3;</span>
    result = (*bqPlayerObject)-&gt;GetInterface(bqPlayerObject, SL_IID_BUFFERQUEUE,
                                             &amp;bqPlayerBufferQueue);
    <span class="hljs-comment">//&#x6CE8;&#x518C;&#x7F13;&#x51B2;&#x961F;&#x5217;&#x56DE;&#x8C03;</span>
    result = (*bqPlayerBufferQueue)-&gt;RegisterCallback(bqPlayerBufferQueue, bqPlayerCallback, <span class="hljs-literal">NULL</span>);
    <span class="hljs-comment">//&#x83B7;&#x53D6;&#x97F3;&#x6548;&#x63A5;&#x53E3;</span>
    result = (*bqPlayerObject)-&gt;GetInterface(bqPlayerObject, SL_IID_EFFECTSEND,
                                             &amp;bqPlayerEffectSend);
    <span class="hljs-comment">//&#x83B7;&#x53D6;&#x97F3;&#x91CF;&#x63A5;&#x53E3;</span>
    result = (*bqPlayerObject)-&gt;GetInterface(bqPlayerObject, SL_IID_VOLUME, &amp;bqPlayerVolume);
    <span class="hljs-comment">//&#x5F00;&#x59CB;&#x64AD;&#x653E;&#x97F3;&#x4E50;</span>
    result = (*bqPlayerPlay)-&gt;SetPlayState(bqPlayerPlay, SL_PLAYSTATE_PLAYING);
}

<span class="hljs-function"><span class="hljs-keyword">int</span> <span class="hljs-title">createAudioPlayer</span><span class="hljs-params">(<span class="hljs-keyword">int</span> *rate, <span class="hljs-keyword">int</span> *channel, <span class="hljs-keyword">const</span> <span class="hljs-keyword">char</span> *file_name)</span>
</span>{
    av_register_all();
    aFormatCtx = avformat_alloc_context();

    <span class="hljs-keyword">if</span> (avformat_open_input(&amp;aFormatCtx, file_name, <span class="hljs-literal">NULL</span>, <span class="hljs-literal">NULL</span>) != <span class="hljs-number">0</span>)
    {
        <span class="hljs-keyword">return</span> <span class="hljs-number">-1</span>;
    }

    <span class="hljs-keyword">if</span> (avformat_find_stream_info(aFormatCtx, <span class="hljs-literal">NULL</span>) &lt; <span class="hljs-number">0</span>) {
        <span class="hljs-keyword">return</span> <span class="hljs-number">-1</span>;
    }

    <span class="hljs-keyword">for</span> (<span class="hljs-keyword">int</span> i = <span class="hljs-number">0</span>; i &lt; aFormatCtx-&gt;nb_streams; i++)
    {
        <span class="hljs-keyword">if</span> (aFormatCtx-&gt;streams[i]-&gt;codec-&gt;codec_type == AVMEDIA_TYPE_AUDIO &amp;&amp; audioStream &lt; <span class="hljs-number">0</span>) {
            audioStream = i;
        }
    }
    <span class="hljs-keyword">if</span> (audioStream == <span class="hljs-number">-1</span>)
    {
        <span class="hljs-keyword">return</span> <span class="hljs-number">-1</span>;
    }
    aCodecCtx = aFormatCtx-&gt;streams[audioStream]-&gt;codec;
    AVCodec *aCodec = avcodec_find_decoder(aCodecCtx-&gt;codec_id);
    <span class="hljs-keyword">if</span> (aCodec==<span class="hljs-literal">NULL</span>)
    {
        <span class="hljs-keyword">return</span> <span class="hljs-number">-1</span>;
    }
    <span class="hljs-keyword">if</span> (avcodec_open2(aCodecCtx, aCodec, <span class="hljs-literal">NULL</span>) &lt; <span class="hljs-number">0</span>)
    {
        <span class="hljs-keyword">return</span> <span class="hljs-number">-1</span>;
    }
    aFrame = av_frame_alloc();

    <span class="hljs-comment">// &#x8BBE;&#x7F6E;&#x683C;&#x5F0F;&#x8F6C;&#x6362; ,  &#x4E5F;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;swr_alloc_set_opts(...)&#x8BBE;&#x7F6E;</span>
    swr = swr_alloc();
    av_opt_set_int(swr, <span class="hljs-string">&quot;in_channel_layout&quot;</span>,  aCodecCtx-&gt;channel_layout, <span class="hljs-number">0</span>);
    av_opt_set_int(swr, <span class="hljs-string">&quot;out_channel_layout&quot;</span>, aCodecCtx-&gt;channel_layout,  <span class="hljs-number">0</span>);
    av_opt_set_int(swr, <span class="hljs-string">&quot;in_sample_rate&quot;</span>,     aCodecCtx-&gt;sample_rate, <span class="hljs-number">0</span>);
    av_opt_set_int(swr, <span class="hljs-string">&quot;out_sample_rate&quot;</span>,    aCodecCtx-&gt;sample_rate, <span class="hljs-number">0</span>);
    av_opt_set_sample_fmt(swr, <span class="hljs-string">&quot;in_sample_fmt&quot;</span>,  aCodecCtx-&gt;sample_fmt, <span class="hljs-number">0</span>);
    av_opt_set_sample_fmt(swr, <span class="hljs-string">&quot;out_sample_fmt&quot;</span>, AV_SAMPLE_FMT_S16,  <span class="hljs-number">0</span>);
    swr_init(swr);

    outputBufferSize = <span class="hljs-number">8196</span>;
    outputBuffer = (<span class="hljs-keyword">uint8_t</span> *) <span class="hljs-built_in">malloc</span>(<span class="hljs-keyword">sizeof</span>(<span class="hljs-keyword">uint8_t</span>) * outputBufferSize);
    <span class="hljs-comment">// &#x8FD4;&#x56DE;sample rate&#x548C;channels</span>
    *rate = aCodecCtx-&gt;sample_rate;
    *channel = aCodecCtx-&gt;channels;
    <span class="hljs-keyword">return</span> <span class="hljs-number">0</span>;
}

<span class="hljs-comment">// &#x83B7;&#x53D6;PCM&#x6570;&#x636E;, &#x81EA;&#x52A8;&#x56DE;&#x8C03;&#x83B7;&#x53D6;</span>
<span class="hljs-function"><span class="hljs-keyword">int</span> <span class="hljs-title">getPCM</span><span class="hljs-params">(<span class="hljs-keyword">void</span> **pcm, size_t *pcmSize)</span>
</span>{
    <span class="hljs-keyword">while</span> (av_read_frame(aFormatCtx, &amp;packet) &gt;= <span class="hljs-number">0</span>)
    {
        <span class="hljs-keyword">int</span> frameFinished = <span class="hljs-number">0</span>;
        <span class="hljs-comment">//&#x97F3;&#x9891;&#x6D41;</span>
        <span class="hljs-keyword">if</span> (packet.stream_index == audioStream)
        {
            avcodec_decode_audio4(aCodecCtx, aFrame, &amp;frameFinished, &amp;packet);
            <span class="hljs-comment">//&#x89E3;&#x7801;&#x5B8C;&#x4E00;&#x5E27;&#x6570;&#x636E;</span>
            <span class="hljs-keyword">if</span> (frameFinished)
            {
                <span class="hljs-comment">// data_size&#x4E3A;&#x97F3;&#x9891;&#x6570;&#x636E;&#x6240;&#x5360;&#x7684;&#x5B57;&#x8282;&#x6570;</span>
                <span class="hljs-keyword">int</span> data_size = av_samples_get_buffer_size(
                        aFrame-&gt;linesize, aCodecCtx-&gt;channels,
                        aFrame-&gt;nb_samples, aCodecCtx-&gt;sample_fmt, <span class="hljs-number">1</span>);

                <span class="hljs-keyword">if</span> (data_size &gt; outputBufferSize)
                {
                    outputBufferSize = (<span class="hljs-keyword">size_t</span>) data_size;
                    outputBuffer = (<span class="hljs-keyword">uint8_t</span> *) <span class="hljs-built_in">realloc</span>(outputBuffer, <span class="hljs-keyword">sizeof</span>(<span class="hljs-keyword">uint8_t</span>) * outputBufferSize);
                }

                <span class="hljs-comment">// &#x97F3;&#x9891;&#x683C;&#x5F0F;&#x8F6C;&#x6362;</span>
                swr_convert(swr, &amp;outputBuffer, aFrame-&gt;nb_samples,
                            (<span class="hljs-keyword">uint8_t</span> <span class="hljs-keyword">const</span> **) (aFrame-&gt;extended_data),
                            aFrame-&gt;nb_samples);

                <span class="hljs-comment">// &#x8FD4;&#x56DE;pcm&#x6570;&#x636E;</span>
                *pcm = outputBuffer;
                *pcmSize = (<span class="hljs-keyword">size_t</span>) data_size;
                <span class="hljs-keyword">return</span> <span class="hljs-number">0</span>;
            }
        }
    }
    <span class="hljs-keyword">return</span> <span class="hljs-number">-1</span>;
}

<span class="hljs-comment">// &#x91CA;&#x653E;&#x76F8;&#x5173;&#x8D44;&#x6E90;</span>
<span class="hljs-function"><span class="hljs-keyword">int</span> <span class="hljs-title">releaseAudioPlayer</span><span class="hljs-params">()</span>
</span>{
    av_packet_unref(&amp;packet);
    av_free(outputBuffer);
    av_free(aFrame);
    avcodec_close(aCodecCtx);
    avformat_close_input(&amp;aFormatCtx);
    <span class="hljs-keyword">return</span> <span class="hljs-number">0</span>;
}

<span class="hljs-comment">// &#x5BF9;&#x5916;&#x64AD;&#x653E;&#x63A5;&#x53E3; &#xFF0C;&#x4F20;&#x5165; mp3 &#x7EDD;&#x5BF9;&#x5730;&#x5740;</span>
<span class="hljs-function">JNIEXPORT <span class="hljs-keyword">void</span> JNICALL <span class="hljs-title">Java_com_frank_ffmpeg_AudioPlayer_playAudio</span>
        <span class="hljs-params">(JNIEnv * env, jclass jobject, jstring filePath)</span>
</span>{
    <span class="hljs-keyword">int</span> rate, channel;
    <span class="hljs-keyword">const</span> <span class="hljs-keyword">char</span> *file_name = (*env)-&gt;GetStringUTFChars(env, filePath, <span class="hljs-literal">NULL</span>);
    <span class="hljs-comment">// &#x521B;&#x5EFA;&#x97F3;&#x9891;&#x89E3;&#x7801;&#x5668;</span>
    createAudioPlayer(&amp;rate, &amp;channel, file_name);
    <span class="hljs-comment">// &#x521B;&#x5EFA;OpenSLES&#x5F15;&#x64CE;</span>
    createEngine();
    <span class="hljs-comment">// &#x521B;&#x5EFA;&#x5E26;&#x6709;&#x7F13;&#x51B2;&#x961F;&#x5217;&#x7684;&#x97F3;&#x9891;&#x64AD;&#x653E;&#x5668;</span>
    createBufferQueueAudioPlayer(rate, channel, SL_PCMSAMPLEFORMAT_FIXED_16);
    <span class="hljs-comment">// &#x542F;&#x52A8;&#x97F3;&#x9891;&#x64AD;&#x653E;</span>
    bqPlayerCallback(bqPlayerBufferQueue, <span class="hljs-literal">NULL</span>);
}

<span class="hljs-comment">//&#x505C;&#x6B62;&#x64AD;&#x653E;&#xFF0C;&#x91CA;&#x653E;&#x76F8;&#x5173;&#x8D44;&#x6E90;</span>
<span class="hljs-function">JNIEXPORT jint JNICALL <span class="hljs-title">Java_com_frank_ffmpeg_AudioPlayer_stop</span>
        <span class="hljs-params">(JNIEnv * env, jclass jobject)</span> </span>{
    <span class="hljs-keyword">if</span> (bqPlayerObject != <span class="hljs-literal">NULL</span>) {
        (*bqPlayerObject)-&gt;Destroy(bqPlayerObject);
        bqPlayerObject = <span class="hljs-literal">NULL</span>;
        bqPlayerPlay = <span class="hljs-literal">NULL</span>;
        bqPlayerBufferQueue = <span class="hljs-literal">NULL</span>;
        bqPlayerEffectSend = <span class="hljs-literal">NULL</span>;
        bqPlayerVolume = <span class="hljs-literal">NULL</span>;
    }

    <span class="hljs-keyword">if</span> (outputMixObject != <span class="hljs-literal">NULL</span>) {
        (*outputMixObject)-&gt;Destroy(outputMixObject);
        outputMixObject = <span class="hljs-literal">NULL</span>;
        outputMixEnvironmentalReverb = <span class="hljs-literal">NULL</span>;
    }

    <span class="hljs-keyword">if</span> (engineObject != <span class="hljs-literal">NULL</span>) {
        (*engineObject)-&gt;Destroy(engineObject);
        engineObject = <span class="hljs-literal">NULL</span>;
        engineEngine = <span class="hljs-literal">NULL</span>;
    }

    <span class="hljs-comment">// &#x91CA;&#x653E;&#x89E3;&#x7801;&#x5668;&#x76F8;&#x5173;&#x8D44;&#x6E90;</span>
    releaseAudioPlayer();
}
</code></pre>
<h3 id="&#x64AD;&#x653E;&#x672C;&#x5730;mp4"><a name="&#x64AD;&#x653E;&#x672C;&#x5730;mp4" class="anchor-navigation-ex-anchor" href="#&#x64AD;&#x653E;&#x672C;&#x5730;mp4"><i class="fa fa-link" aria-hidden="true"></i></a>1.1.10. &#x64AD;&#x653E;&#x672C;&#x5730;MP4</h3>
<pre><code class="lang-c">#define MAX_AUDIO_FRAME_SIZE 48000 * 4
#define PACKET_SIZE 50
#define MIN_SLEEP_TIME_US 1000ll
#define AUDIO_TIME_ADJUST_US -200000ll

typedef struct MediaPlayer{
    AVFormatContext* format_context;
    int video_stream_index;
    int audio_stream_index;
    AVCodecContext* video_codec_context;
    AVCodecContext* audio_codec_context;
    AVCodec* video_codec;
    AVCodec* audio_codec;
    ANativeWindow* native_window;
    uint8_t* buffer;
    AVFrame* yuv_frame;
    AVFrame* rgba_frame;
    int video_width;
    int video_height;
    SwrContext* swrContext;
    int out_channel_nb;
    int out_sample_rate;
    enum AVSampleFormat out_sample_fmt;
    jobject audio_track;
    jmethodID audio_track_write_mid;
    uint8_t* audio_buffer;
    AVFrame* audio_frame;
    AVPacketQueue* packets[2];
    pthread_mutex_t mutex;
    pthread_cond_t cond;
    int64_t start_time;
    int64_t audio_clock;
    pthread_t write_thread;
    pthread_t video_thread;
    pthread_t audio_thread;
}MediaPlayer;

typedef struct Decoder{
    MediaPlayer* player;
    int stream_index;
}Decoder;

JavaVM* javaVM;
MediaPlayer* player;


jint JNICALL JNI_OnLoad(JavaVM* vm, void* reserved)
{
    javaVM = vm;
    return JNI_VERSION_1_6;
}

int init_input_format_context(MediaPlayer* player, const char* file_name)
{
    av_register_all();
    player-&gt;format_context = avformat_alloc_context();
    if(avformat_open_input(&amp;player-&gt;format_context, file_name, NULL, NULL)!=0)
    {
        return -1;
    }
    //&#x67E5;&#x627E;&#x662F;&#x5426;&#x6709;&#x97F3;&#x9891; &#x6216; &#x89C6;&#x9891;&#x4FE1;&#x606F;
    if(avformat_find_stream_info(player-&gt;format_context, NULL)&lt;0)
    {
        return -1;
    }
    //&#x5BFB;&#x627E;&#x97F3;&#x89C6;&#x9891;&#x6D41;&#x7D22;&#x5F15;&#x4F4D;&#x7F6E;
    player-&gt;video_stream_index = -1;
    player-&gt;audio_stream_index = -1;
    for (int i = 0; i &lt; player-&gt;format_context-&gt;nb_streams; i++)
    {
        if (player-&gt;format_context-&gt;streams[i]-&gt;codec-&gt;codec_type == AVMEDIA_TYPE_VIDEO &amp;&amp; player-&gt;video_stream_index &lt; 0)
        {
            player-&gt;video_stream_index = i;
        } else if (player-&gt;format_context-&gt;streams[i]-&gt;codec-&gt;codec_type == AVMEDIA_TYPE_AUDIO &amp;&amp; player-&gt;audio_stream_index &lt; 0) {
            player-&gt;audio_stream_index = i;
        }
    }
    if(player-&gt;video_stream_index==-1)
    {
        // &#x6CA1;&#x6709;&#x89C6;&#x9891;&#x4FE1;&#x606F;
        return -1;
    }
    if(player-&gt;audio_stream_index==-1)
    {
       // &#x6CA1;&#x6709;&#x97F3;&#x9891;&#x4FE1;&#x606F;
        return -1;
    }
    return 0;
}

//&#x6253;&#x5F00;&#x97F3;&#x89C6;&#x9891;&#x89E3;&#x7801;&#x5668;
int init_condec_context(MediaPlayer* player)
{
    //&#x83B7;&#x53D6;codec&#x4E0A;&#x4E0B;&#x6587;&#x6307;&#x9488;
    player-&gt;video_codec_context = player-&gt;format_context-&gt;streams[player-&gt;video_stream_index]-&gt;codec;
    //&#x5BFB;&#x627E;&#x89C6;&#x9891;&#x6D41;&#x7684;&#x89E3;&#x7801;&#x5668;
    player-&gt;video_codec = avcodec_find_decoder(player-&gt;video_codec_context-&gt;codec_id);
    if(player-&gt;video_codec == NULL)
    {
        return -1;
    }
    // &#x6253;&#x5F00;&#x89E3;&#x7801;&#x5668;
    if(avcodec_open2(player-&gt;video_codec_context, player-&gt;video_codec, NULL) &lt; 0)
    {
        return -1;
    }
    player-&gt;audio_codec_context = player-&gt;format_context-&gt;streams[player-&gt;audio_stream_index]-&gt;codec;
    player-&gt;audio_codec = avcodec_find_decoder(player-&gt;audio_codec_context-&gt;codec_id);
    if( player-&gt;audio_codec == NULL)
    {
        return -1;
    }
    if(avcodec_open2(player-&gt;audio_codec_context, player-&gt;audio_codec, NULL) &lt; 0)
    {
        return -1;
    }
    // &#x83B7;&#x53D6;&#x89C6;&#x9891;&#x5BBD;&#x9AD8;
    player-&gt;video_width = player-&gt;video_codec_context-&gt;width;
    player-&gt;video_height = player-&gt;video_codec_context-&gt;height;
    return 0;
}

// &#x83B7;&#x5F97; ANativeWindow  surface
void video_player_prepare(MediaPlayer* player, JNIEnv* env, jobject surface)
{
    player-&gt;native_window = ANativeWindow_fromSurface(env, surface);
}

//&#x83B7;&#x53D6;&#x5F53;&#x524D;&#x64AD;&#x653E;&#x65F6;&#x95F4;
int64_t get_play_time(MediaPlayer* player){
    return (int64_t)(av_gettime() - player-&gt;start_time);
}

// &#x97F3;&#x89C6;&#x9891;&#x540C;&#x6B65;
void player_wait_for_frame(MediaPlayer *player, int64_t stream_time)
{
    pthread_mutex_lock(&amp;player-&gt;mutex);
    for(;;){
        int64_t current_video_time = get_play_time(player);
        int64_t sleep_time = stream_time - current_video_time;
        if (sleep_time &lt; -300000ll) {
            // 300 ms late
            int64_t new_value = player-&gt;start_time - sleep_time;
            player-&gt;start_time = new_value;
            pthread_cond_broadcast(&amp;player-&gt;cond);
        }

        if (sleep_time &lt;= MIN_SLEEP_TIME_US) {
            // We do not need to wait if time is slower then minimal sleep time
            break;
        }

        if (sleep_time &gt; 500000ll) {
            // if sleep time is bigger then 500ms just sleep this 500ms
            // and check everything again
            sleep_time = 500000ll;
        }
        //&#x7B49;&#x5F85;&#x6307;&#x5B9A;&#x65F6;&#x957F;
        pthread_cond_timeout_np(&amp;player-&gt;cond, &amp;player-&gt;mutex,
                                                  (unsigned int) (sleep_time / 1000ll));
    }
    pthread_mutex_unlock(&amp;player-&gt;mutex);
}

//&#x89C6;&#x9891;&#x89E3;&#x7801;
int decode_video(MediaPlayer* player, AVPacket* packet)
{
    ANativeWindow_setBuffersGeometry(player-&gt;native_window,  player-&gt;video_width,
                                     player-&gt;video_height, WINDOW_FORMAT_RGBA_8888);

    ANativeWindow_Buffer windowBuffer;
    player-&gt;yuv_frame = av_frame_alloc();
    player-&gt;rgba_frame = av_frame_alloc();
    if(player-&gt;rgba_frame == NULL || player-&gt;yuv_frame == NULL)
    {
        return -1;
    }

    // buffer&#x4E2D;&#x6570;&#x636E;&#x7528;&#x4E8E;&#x6E32;&#x67D3;,&#x4E14;&#x683C;&#x5F0F;&#x4E3A;RGBA
    int numBytes=av_image_get_buffer_size(AV_PIX_FMT_RGBA, player-&gt;video_width, player-&gt;video_height, 1);

    player-&gt;buffer = (uint8_t *)av_malloc(numBytes*sizeof(uint8_t));
    av_image_fill_arrays(player-&gt;rgba_frame-&gt;data,
                         player-&gt;rgba_frame-&gt;linesize,
                         player-&gt;buffer,
                         AV_PIX_FMT_RGBA,
                         player-&gt;video_width,
                         player-&gt;video_height,
                         1);

    // &#x7531;&#x4E8E;&#x89E3;&#x7801;&#x51FA;&#x6765;&#x7684;&#x5E27;&#x683C;&#x5F0F;&#x4E0D;&#x662F;RGBA&#x7684;,&#x5728;&#x6E32;&#x67D3;&#x4E4B;&#x524D;&#x9700;&#x8981;&#x8FDB;&#x884C;&#x683C;&#x5F0F;&#x8F6C;&#x6362;
    struct SwsContext *sws_ctx = sws_getContext(
            player-&gt;video_width,
            player-&gt;video_height,
            player-&gt;video_codec_context-&gt;pix_fmt,
            player-&gt;video_width,
            player-&gt;video_height,
            AV_PIX_FMT_RGBA,
            SWS_BILINEAR,
            NULL,
            NULL,
            NULL);

    int frameFinished;
    //&#x89E3;&#x7801;
    int ret = avcodec_decode_video2(player-&gt;video_codec_context, player-&gt;yuv_frame, &amp;frameFinished, packet);
    if(ret &lt; 0)
    {
        return -1;
    }
    if (frameFinished) {
        // lock native window
        ANativeWindow_lock(player-&gt;native_window, &amp;windowBuffer, 0);
        // &#x683C;&#x5F0F;&#x8F6C;&#x6362;
        sws_scale(sws_ctx, (uint8_t const * const *)player-&gt;yuv_frame-&gt;data,
                  player-&gt;yuv_frame-&gt;linesize, 0, player-&gt;video_height,
                  player-&gt;rgba_frame-&gt;data, player-&gt;rgba_frame-&gt;linesize);
        // &#x83B7;&#x53D6;stride
        uint8_t * dst = windowBuffer.bits;
        int dstStride = windowBuffer.stride * 4;
        uint8_t * src = player-&gt;rgba_frame-&gt;data[0];
        int srcStride = player-&gt;rgba_frame-&gt;linesize[0];
        // &#x7531;&#x4E8E;window&#x7684;stride&#x548C;&#x5E27;&#x7684;stride&#x4E0D;&#x540C;,&#x56E0;&#x6B64;&#x9700;&#x8981;&#x9010;&#x884C;&#x590D;&#x5236;
        int h;
        for (h = 0; h &lt; player-&gt;video_height; h++)
        {
            memcpy(dst + h * dstStride, src + h * srcStride, (size_t) srcStride);
        }

        //&#x8BA1;&#x7B97;&#x5EF6;&#x8FDF;
        int64_t pts = av_frame_get_best_effort_timestamp(player-&gt;yuv_frame);
        AVStream *stream = player-&gt;format_context-&gt;streams[player-&gt;video_stream_index];
        //&#x8F6C;&#x6362;&#xFF08;&#x4E0D;&#x540C;&#x65F6;&#x95F4;&#x57FA;&#x65F6;&#x95F4;&#x8F6C;&#x6362;&#xFF09;
        int64_t time = av_rescale_q(pts, stream-&gt;time_base, AV_TIME_BASE_Q);
        //&#x97F3;&#x89C6;&#x9891;&#x5E27;&#x540C;&#x6B65;
        player_wait_for_frame(player, time);
        ANativeWindow_unlockAndPost(player-&gt;native_window);
    }
    return 0;
}

//&#x97F3;&#x9891;&#x89E3;&#x7801;&#x521D;&#x59CB;&#x5316;
void audio_decoder_prepare(MediaPlayer* player)
{
    //frame-&gt;16bit 44100 PCM &#x7EDF;&#x4E00;&#x97F3;&#x9891;&#x91C7;&#x6837;&#x683C;&#x5F0F;&#x4E0E;&#x91C7;&#x6837;&#x7387;
    player-&gt;swrContext = swr_alloc();
    //&#x8F93;&#x5165;&#x7684;&#x91C7;&#x6837;&#x683C;&#x5F0F;
    enum AVSampleFormat in_sample_fmt = player-&gt;audio_codec_context-&gt;sample_fmt;
    //&#x8F93;&#x51FA;&#x91C7;&#x6837;&#x683C;&#x5F0F;16bit PCM
    player-&gt;out_sample_fmt = AV_SAMPLE_FMT_S16;
    //&#x8F93;&#x5165;&#x91C7;&#x6837;&#x7387;
    int in_sample_rate = player-&gt;audio_codec_context-&gt;sample_rate;
    //&#x8F93;&#x51FA;&#x91C7;&#x6837;&#x7387;
    player-&gt;out_sample_rate = in_sample_rate;
    //&#x58F0;&#x9053;&#x5E03;&#x5C40;&#xFF08;2&#x4E2A;&#x58F0;&#x9053;&#xFF0C;&#x9ED8;&#x8BA4;&#x7ACB;&#x4F53;&#x58F0;stereo&#xFF09;
    uint64_t in_ch_layout = player-&gt;audio_codec_context-&gt;channel_layout;
    //&#x8F93;&#x51FA;&#x7684;&#x58F0;&#x9053;&#x5E03;&#x5C40;&#xFF08;&#x7ACB;&#x4F53;&#x58F0;&#xFF09;
    uint64_t out_ch_layout = AV_CH_LAYOUT_STEREO;
    swr_alloc_set_opts(player-&gt;swrContext,
                       out_ch_layout, player-&gt;out_sample_fmt, player-&gt;out_sample_rate,
                       in_ch_layout, in_sample_fmt, in_sample_rate,
                       0, NULL);
    swr_init(player-&gt;swrContext);
    //&#x8F93;&#x51FA;&#x7684;&#x58F0;&#x9053;&#x4E2A;&#x6570;
    player-&gt;out_channel_nb = av_get_channel_layout_nb_channels(out_ch_layout);
}

//&#x97F3;&#x9891;&#x64AD;&#x653E;&#x5668;
void audio_player_prepare(MediaPlayer* player, JNIEnv* env, jclass jthiz)
{
    jclass player_class = (*env)-&gt;GetObjectClass(env,jthiz);
    if(!player_class)
    {
       return ;
    }
    // &#x6839;&#x636E;&#x81EA;&#x5B9A;&#x4E49;&#x7684;java&#x65B9;&#x6CD5; createAudioTrack &#x83B7;&#x53D6; android &#x81EA;&#x5E26;&#x7684; AudioTrack &#x5BF9;&#x8C61;
    jmethodID audio_track_method = (*env)-&gt;GetMethodID(env,player_class,&quot;createAudioTrack&quot;,&quot;(II)Landroid/media/AudioTrack;&quot;);
    if(!audio_track_method)
    {
        return ;
    }
    jobject audio_track = (*env)-&gt;CallObjectMethod( env,jthiz,audio_track_method, player-&gt;out_sample_rate, player-&gt;out_channel_nb);
    //&#x8C03;&#x7528; AudioTrack &#x7684;play()&#x65B9;&#x6CD5;
    jclass audio_track_class = (*env)-&gt;GetObjectClass(env, audio_track);
    jmethodID audio_track_play_mid = (*env)-&gt;GetMethodID(env,audio_track_class,&quot;play&quot;,&quot;()V&quot;);
    (*env)-&gt;CallVoidMethod(env, audio_track, audio_track_play_mid);

    player-&gt;audio_track = (*env)-&gt;NewGlobalRef(env, audio_track);
    //&#x83B7;&#x53D6; AudioTrack &#x7684; write()&#x65B9;&#x6CD5;
    player-&gt;audio_track_write_mid = (*env)-&gt;GetMethodID(env,audio_track_class,&quot;write&quot;,&quot;([BII)I&quot;);
    //16bit 44100 PCM &#x6570;&#x636E;
    player-&gt;audio_buffer = (uint8_t *)av_malloc(MAX_AUDIO_FRAME_SIZE);
    //&#x89E3;&#x7801;&#x540E;&#x7684;&#x97F3;&#x9891;&#x6570;&#x636E;
    player-&gt;audio_frame = av_frame_alloc();
}

//&#x97F3;&#x9891;&#x89E3;&#x7801; + &#x64AD;&#x653E;
int decode_audio(MediaPlayer* player, AVPacket* packet)
{
    int got_frame = 0, ret;
    //&#x89E3;&#x7801;
    ret = avcodec_decode_audio4(player-&gt;audio_codec_context, player-&gt;audio_frame, &amp;got_frame, packet);
    if(ret &lt; 0)
    {
        return -1;
    }
    //&#x89E3;&#x7801;&#x4E00;&#x5E27;&#x6210;&#x529F;
    if(got_frame &gt; 0)
    {
        //&#x97F3;&#x9891;&#x683C;&#x5F0F;&#x8F6C;&#x6362;
        swr_convert(player-&gt;swrContext, &amp;player-&gt;audio_buffer,  MAX_AUDIO_FRAME_SIZE, (const uint8_t **)player-&gt;audio_frame-&gt;data, player-&gt;audio_frame-&gt;nb_samples);
        int out_buffer_size = av_samples_get_buffer_size(NULL,
                                                         player-&gt;out_channel_nb,
                                                         player-&gt;audio_frame-&gt;nb_samples,
                                                         player-&gt;out_sample_fmt,
                                                         1);

        //&#x97F3;&#x89C6;&#x9891;&#x5E27;&#x540C;&#x6B65;
        int64_t pts = packet-&gt;pts;
        // AV_NOPTS_VALUE  &#x65E0;&#x6548;&#x7684;pts &#x6807;&#x8BB0;
        if (pts != AV_NOPTS_VALUE)
        {
            AVStream *stream = player-&gt;format_context-&gt;streams[player-&gt;audio_stream_index];
            // av_rescale_q  AV_TIME_BASE_Q
            player-&gt;audio_clock = av_rescale_q(pts, stream-&gt;time_base, AV_TIME_BASE_Q);
            player_wait_for_frame(player, player-&gt;audio_clock + AUDIO_TIME_ADJUST_US);
        }

        if(javaVM != NULL)
        {
            JNIEnv * env;
            (*javaVM)-&gt;AttachCurrentThread(javaVM, &amp;env, NULL);
            jbyteArray audio_sample_array = (*env)-&gt;NewByteArray(env,out_buffer_size);
            jbyte* sample_byte_array = (*env)-&gt;GetByteArrayElements(env,audio_sample_array,NULL);
            memcpy(sample_byte_array, player-&gt;audio_buffer, (size_t) out_buffer_size);
            (*env)-&gt;ReleaseByteArrayElements(env,audio_sample_array,sample_byte_array,0);
            //&#x8C03;&#x7528;AudioTrack&#x7684;write&#x65B9;&#x6CD5;&#x8FDB;&#x884C;&#x64AD;&#x653E;
            (*env)-&gt;CallIntMethod(env, player-&gt;audio_track, player-&gt;audio_track_write_mid, audio_sample_array,0,out_buffer_size);
            (*env)-&gt;DeleteLocalRef(env,audio_sample_array);
        }
    }
    if(javaVM != NULL)
    {
        (*javaVM)-&gt;DetachCurrentThread(javaVM);
    }
    return 0;
}

//&#x521D;&#x59CB;&#x5316;&#x961F;&#x5217;
void init_queue(MediaPlayer* player, int size)
{
    for (int i = 0; i &lt; 2; ++i)
    {
        AVPacketQueue* queue = queue_init(size);
        player-&gt;packets[i] = queue;
    }
}

//&#x91CA;&#x653E;&#x961F;&#x5217;
void delete_queue(MediaPlayer* player){
    int i;
    for (i = 0; i &lt; 2; ++i) {
        queue_free(player-&gt;packets[i]);
    }
}

//&#x8BFB;&#x53D6;AVPacket&#x7EBF;&#x7A0B;(&#x751F;&#x4EA7;&#x8005;) &#xFF0C; &#x83B7;&#x5F97;&#x89E3;&#x7801;&#x4E4B;&#x524D;&#x7684;&#x97F3;&#x9891;&#x6570;&#x636E;+&#x89C6;&#x9891;&#x6570;&#x636E;
void* write_packet_to_queue(void* arg)
{
    MediaPlayer* player = (MediaPlayer*)arg;
    AVPacket packet ;
    AVPacket *pkt = &amp;packet;
    for(;;)
    {
        int ret = av_read_frame(player-&gt;format_context, pkt);
        if(ret &lt; 0)
        {
            break;
        }
        if(pkt-&gt;stream_index == player-&gt;video_stream_index || pkt-&gt;stream_index == player-&gt;audio_stream_index)
        {
            // &#x5C06; &#x6BCF;&#x4E00;&#x5E27; &#x89E3;&#x7801;&#x524D;&#x7684; &#x6570;&#x636E; &#x5206;&#x522B;&#x5B58;&#x5230; &#x97F3;&#x9891; &#x548C;&#x89C6;&#x9891;&#x7684;&#x7F13;&#x51B2;&#x961F;&#x5217;&#x4E2D;
            AVPacketQueue *queue = player-&gt;packets[pkt-&gt;stream_index];
            pthread_mutex_lock(&amp;player-&gt;mutex);
            AVPacket* data = queue_push(queue, &amp;player-&gt;mutex, &amp;player-&gt;cond);
            pthread_mutex_unlock(&amp;player-&gt;mutex);
            *data = packet;
        }
    }
}


//&#x6839;&#x636E;&#x53C2;&#x6570; &#x89E3;&#x7801;&#x97F3;&#x9891; &#x6216; &#x89C6;&#x9891;
void* decode_func(void* arg)
{
    Decoder *decoder_data = (Decoder*)arg;
    MediaPlayer *player = decoder_data-&gt;player;
    int stream_index = decoder_data-&gt;stream_index;
    AVPacketQueue *queue = player-&gt;packets[stream_index];

    for(;;)
    {
        pthread_mutex_lock(&amp;player-&gt;mutex);
        AVPacket *packet = (AVPacket*)queue_pop(queue, &amp;player-&gt;mutex, &amp;player-&gt;cond);
        pthread_mutex_unlock(&amp;player-&gt;mutex);

        int ret = 0;
        if(stream_index == player-&gt;video_stream_index) {
            // &#x89E3;&#x7801; &#x89C6;&#x9891;
            ret = decode_video(player, packet);
        } else if(stream_index == player-&gt;audio_stream_index)
        {
            // &#x89E3;&#x7801; &#x97F3;&#x9891;
            ret = decode_audio(player, packet);
        }
        av_packet_unref(packet);
        if(ret &lt; 0)
        {
            break;
        }
    }
}


// &#x5BF9;&#x5916;&#x63A5;&#x53E3; &#xFF0C;&#x521D;&#x59CB;&#x5316; &#x64AD;&#x653E;&#x5668;
JNIEXPORT jint JNICALL Java_com_frank_ffmpeg_MediaPlayer_setup
        (JNIEnv * env, jclass clazz, jstring filePath, jobject surface)
{

    const char *file_name = (*env)-&gt;GetStringUTFChars(env, filePath, JNI_FALSE);
    player = malloc(sizeof(MediaPlayer));
    if(player == NULL)
    {
        return -1;
    }
    //&#x521D;&#x59CB;&#x5316;&#x8F93;&#x5165;&#x683C;&#x5F0F;&#x4E0A;&#x4E0B;&#x6587;
    int ret = init_input_format_context(player, file_name);
    if(ret &lt; 0)
    {
        return -1;
    }
    //&#x521D;&#x59CB;&#x5316;&#x97F3;&#x89C6;&#x9891;&#x89E3;&#x7801;&#x5668;
    ret = init_condec_context(player);
    if(ret &lt; 0)
    {
        return -1;
    }
    //&#x521D;&#x59CB;&#x5316;&#x89C6;&#x9891;surface
    video_player_prepare( player, env, surface);
    //&#x521D;&#x59CB;&#x5316;&#x97F3;&#x9891;&#x76F8;&#x5173;&#x53C2;&#x6570;
    audio_decoder_prepare(player);
    //&#x521D;&#x59CB;&#x5316;&#x97F3;&#x9891;&#x64AD;&#x653E;&#x5668;
    audio_player_prepare(player, env,  clazz);
    //&#x521D;&#x59CB;&#x5316;&#x97F3;&#x89C6;&#x9891;packet&#x961F;&#x5217;
    init_queue(player, PACKET_SIZE);
    return 0;
}

// &#x5BF9;&#x5916;&#x63A5;&#x53E3; &#xFF0C; &#x64AD;&#x653E;&#x97F3;&#x89C6;&#x9891;
JNIEXPORT jint JNICALL Java_com_frank_ffmpeg_MediaPlayer_play (JNIEnv * env, jclass clazz)
{
    pthread_mutex_init(&amp;player-&gt;mutex, NULL);
    pthread_cond_init(&amp;player-&gt;cond, NULL);

    // &#x83B7;&#x5F97;&#x89E3;&#x7801;&#x524D;&#x7684; &#x97F3;&#x9891;&#x6570;&#x636E; &#x548C;&#x89C6;&#x9891;&#x6570;&#x636E; &#xFF0C; &#x5B50;&#x7EBF;&#x7A0B;
    pthread_create(&amp;player-&gt;write_thread, NULL, write_packet_to_queue, (void*)player);
    sleep(1);
    player-&gt;start_time = 0;

    //&#x89E3;&#x7801;&#x89C6;&#x9891; &#xFF0C; &#x5B50;&#x7EBF;&#x7A0B;
    Decoder data1 = {player, player-&gt;video_stream_index} ;
    Decoder *decoder_data1 = &amp;data1;
    pthread_create(&amp;player-&gt;video_thread, NULL, decode_func, (void*)decoder_data1);

    // &#x89E3;&#x7801;&#x97F3;&#x9891; &#xFF0C; &#x5B50;&#x7EBF;&#x7A0B;
    Decoder data2 = {player, player-&gt;audio_stream_index} ;
    Decoder *decoder_data2 = &amp;data2;
    pthread_create(&amp;player-&gt;audio_thread,NULL,decode_func,(void*)decoder_data2);

    pthread_join(player-&gt;write_thread, NULL);
    pthread_join(player-&gt;video_thread, NULL);
    pthread_join(player-&gt;audio_thread, NULL);

    return 0;
}

// &#x91CA;&#x653E;&#x8D44;&#x6E90;
JNIEXPORT void JNICALL Java_com_frank_ffmpeg_MediaPlayer_release
        (JNIEnv * env, jclass clazz)
{
    //&#x91CA;&#x653E;&#x5185;&#x5B58;&#x4EE5;&#x53CA;&#x5173;&#x95ED;&#x6587;&#x4EF6;
    free(player-&gt;audio_track);
    free(player-&gt;audio_track_write_mid);
    av_free(player-&gt;buffer);
    av_free(player-&gt;rgba_frame);
    av_free(player-&gt;yuv_frame);
    av_free(player-&gt;audio_buffer);
    av_free(player-&gt;audio_frame);
    avcodec_close(player-&gt;video_codec_context);
    avcodec_close(player-&gt;audio_codec_context);
    avformat_close_input(&amp;player-&gt;format_context);
    ANativeWindow_release(player-&gt;native_window);
    delete_queue(player);
    pthread_cond_destroy(&amp;player-&gt;cond);
    pthread_mutex_destroy(&amp;player-&gt;mutex);
    free(player);
    (*javaVM)-&gt;DestroyJavaVM(javaVM);
}
</code></pre>
<pre><code class="lang-java"><span class="hljs-function"><span class="hljs-keyword">public</span> AudioTrack <span class="hljs-title">createAudioTrack</span><span class="hljs-params">(<span class="hljs-keyword">int</span> sampleRate, <span class="hljs-keyword">int</span> channels)</span></span>{
    <span class="hljs-keyword">int</span> audioFormat = AudioFormat.ENCODING_PCM_16BIT;
    <span class="hljs-keyword">int</span> channelConfig;
    <span class="hljs-keyword">if</span>(channels == <span class="hljs-number">1</span>){
        channelConfig = android.media.AudioFormat.CHANNEL_OUT_MONO;
    }<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span>(channels == <span class="hljs-number">2</span>){
        channelConfig = android.media.AudioFormat.CHANNEL_OUT_STEREO;
    }<span class="hljs-keyword">else</span>{
        channelConfig = android.media.AudioFormat.CHANNEL_OUT_STEREO;
    }

    <span class="hljs-comment">//  &#x8FD4;&#x56DE;&#x97F3;&#x8F68;&#x6240;&#x9700;&#x7684;&#x4F30;&#x8BA1;&#x6700;&#x5C0F;&#x7F13;&#x51B2;&#x533A;&#x5927;&#x5C0F;    </span>
    <span class="hljs-keyword">int</span> bufferSizeInBytes = AudioTrack.getMinBufferSize(sampleRate, channelConfig, audioFormat);

    <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> AudioTrack(AudioManager.STREAM_MUSIC, sampleRate, channelConfig, audioFormat,
            bufferSizeInBytes, AudioTrack.MODE_STREAM);
}
</code></pre>
<footer class="page-footer"><span class="copyright">&#x65E0;&#x7248;&#x6743; &#x53EF;&#x4EE5;&#x65E0;&#x9650;&#x5236;&#x4F7F;&#x7528;&#xFF01; all right reserved&#xFF0C;powered by Gitbook</span><span class="footer-modification">&#x8BE5;&#x6587;&#x4EF6;&#x66F4;&#x65B0;&#x65F6;&#x95F4;&#xFF1A;
2020-08-20 14:17:31
</span></footer>
                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="ffmpeg基础.html" class="navigation navigation-prev " aria-label="Previous page: ffmpeg基础">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="ffmpeg软解rtsp简单直播.html" class="navigation navigation-next " aria-label="Next page: ffmpeg软解rtsp简单直播">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"ffmpeg示例代码","level":"1.8.2","depth":2,"next":{"title":"ffmpeg软解rtsp简单直播","level":"1.8.3","depth":2,"path":"chinese/ffmpeg/ffmpeg软解rtsp简单直播.md","ref":"chinese/ffmpeg/ffmpeg软解rtsp简单直播.md","articles":[]},"previous":{"title":"ffmpeg基础","level":"1.8.1","depth":2,"path":"chinese/ffmpeg/ffmpeg基础.md","ref":"chinese/ffmpeg/ffmpeg基础.md","articles":[]},"dir":"ltr"},"config":{"plugins":["-search","search-plus","todo","anchor-navigation-ex","copy-code-button","versions-select","fontsettings","sharing","tbfed-pagefooter","donate","local-video","splitter","edit-link","expandable-chapters","favicon","theme-comscore","local-video"],"styles":{"website":"styles/website.css"},"pluginsConfig":{"tbfed-pagefooter":{"copyright":"无版权 可以无限制使用！","modify_label":"该文件更新时间：","modify_format":"YYYY-MM-DD HH:mm:ss"},"todo":{},"splitter":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"versions-select":{"type":"branches"},"donate":{"alipay":"https://gitee.com/hnyer/filesOfGitbook/raw/master/files/201803011956_osChina_支付宝收款码.png","alipayText":"支付宝打赏","button":"打赏","title":"","wechat":"https://gitee.com/hnyer/filesOfGitbook/raw/master/files/201803011956_osChina_微信收款码.png","wechatText":"微信打赏"},"fontsettings":{"family":"sans","size":2,"theme":"sepia"},"highlight":{},"anchor-navigation-ex":{"associatedWithSummary":true,"float":{"floatIcon":"fa fa-navicon","level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"mode":"float","multipleH1":true,"pageTop":{"level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"printLog":false,"showGoTop":true,"showLevel":true},"favicon":{"shortcut":"assets/images/favicon.ico","bookmark":"assets/images/favicon.ico"},"theme-comscore":{},"local-video":{},"copy-code-button":{},"versions":{"options":[{"value":"https://www.aivin666.cn/java_android/","text":"v1.0"}]},"sharing":{"all":["facebook","google","twitter","weibo","instapaper"],"facebook":false,"google":true,"instapaper":false,"twitter":false,"vk":false,"weibo":true},"edit-link":{"label":"托管页面","base":"https://www.baidu.com/"},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"expandable-chapters":{},"search-plus":{}},"theme":"default","author":"Aivin","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"Aivin开发笔记","language":"zh-hans","gitbook":"*","description":"Aivin开发笔记"},"file":{"path":"chinese/ffmpeg/ffmpeg示例代码.md","mtime":"2020-08-20T06:17:31.510Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2020-08-20T09:02:41.305Z"},"basePath":"../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-search-plus/jquery.mark.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search-plus/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-copy-code-button/toggle.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-versions-select/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-donate/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-local-video/video.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-edit-link/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-theme-comscore/test.js"></script>
        
    

    </body>
</html>

